apiVersion: monitoring.coreos.com/v1
kind: Prometheus
metadata:
  labels:
    prometheus: k8s
  name: k8s
  namespace: kubesphere-monitoring-system
spec:
  additionalScrapeConfigs:
    key: prometheus-additional.yaml
    name: additional-scrape-configs
  affinity:
    nodeAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - preference:
          matchExpressions:
          - key: node-role.kubernetes.io/monitoring
            operator: Exists
        weight: 100
    podAntiAffinity:
      preferredDuringSchedulingIgnoredDuringExecution:
      - podAffinityTerm:
          labelSelector:
            matchExpressions:
            - key: prometheus
              operator: In
              values:
              - k8s
          namespaces:
          - kubesphere-monitoring-system
          topologyKey: kubernetes.io/hostname
        weight: 100
  alerting:
    alertmanagers:
    - name: alertmanager-main
      namespace: kubesphere-monitoring-system
      port: web
  image: {{ prometheus_repo }}:{{ prometheus_tag }}
  nodeSelector:
{% if prometheus_node_selector_map is defined %}
{{ prometheus_node_selector_map }}
{% else %}
    kubernetes.io/os: linux
{% endif %}
  podMonitorNamespaceSelector: {}
  podMonitorSelector: {}
  query:
    maxConcurrency: 1000
{% if nodeNum is defined and nodeNum < 3 %}
  replicas: {{ monitoring.prometheusReplicas | default(1) }}
{% else %}
  replicas: {{ monitoring.prometheusReplicas | default(2) }}
{% endif %}
  resources:
    limits:
      cpu: "{{ monitoring.prometheus.limits.cpu | default("4") }}"
      memory: {{ monitoring.prometheus.limits.memory | default("16Gi") }}
    requests:
      cpu: {{ monitoring.prometheus.requests.cpu | default("200m") }}
      memory: {{ monitoring.prometheus.requests.memory | default("400Mi") }}
  retention: {% if prometheus_retention_duration is defined %}{{ prometheus_retention_duration }}{% else %}7d{% endif %}

  ruleSelector:
    matchLabels:
      prometheus: k8s
      role: alert-rules
  scrapeInterval: 1m
{% if etcd.monitoring is defined and etcd.monitoring == true %}
  secrets:
  - kube-etcd-client-certs
{% endif %}
  securityContext:
    fsGroup: 0
    runAsNonRoot: false
    runAsUser: 0
  serviceAccountName: prometheus-k8s
  serviceMonitorNamespaceSelector: {}
  serviceMonitorSelector: {}
  storage:
    volumeClaimTemplate:
      spec:
{% if persistence.storageClass is defined and persistence.storageClass != "" %}
        storageClassName: {{ persistence.storageClass }}
{% endif %}
        resources:
          requests:
            storage: {% if prometheus_pv_size is defined %}{{ prometheus_pv_size }}{% else %}{{ monitoring.prometheusVolumeSize }}{% endif %}

  tolerations:
  - effect: NoSchedule
    key: dedicated
    operator: Equal
    value: monitoring
  version: {{ prometheus_tag }}